<template>
    <el-form-item>
        <el-button @click="onSubmit">保存</el-button>
    </el-form-item>
    <h2 style="margin-left: 400px;">报工单据</h2>
    <table class="order-table">
        <tr>
            <th colspan="6" style="text-align: left;">基本信息</th>
        </tr>
        <tr>
            <td>检验标准：</td>
            <td><el-input v-model="form.inspectionStandards" placeholder="请输入检验标准" /></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td>检验结果：</td>
            <td colspan="3"><el-input v-model="form.testResults" type="textarea" placeholder="请输入检验结果"/></td>
        </tr>
        <tr>
            <td>不合格数量：</td>
            <td><el-input v-model="form.unqualifiedNum" placeholder="请输入不合格数量" /></td>
            <td>合格数量：</td>
            <td><el-input v-model="form.hegeNum" placeholder="请输入合格数量" /></td>
        </tr>
        <tr>
            <td>不合格原因：</td>
            <td colspan="3"><el-input v-model="form.unqualifiedCause" type="textarea" placeholder="请输入不合格原因"/></td>
        </tr>
        <tr>
            <td>处理措施：</td>
            <td colspan="3"><el-input v-model="form.unqualifiedMeasure" type="textarea" placeholder="请输入处理措施"/></td>
        </tr>
    </table>
</template>

<script lang="ts" setup>
import { reactive, ref, computed, onMounted } from 'vue'
import dayjs from 'dayjs'
import { useCounterStore } from "@/stores/counter";
import { ElMessage } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'
import axios from 'axios'
import {read,write} from '@/axios/axiosHelper'

const router = useRouter()
const route = useRoute()

const store = useCounterStore();

const form = reactive({
    reportId:route.query.reportId,
    inspectionStandards: '',
    testResults: '',
    unqualifiedNum: '',
    hegeNum: '',
    unqualifiedCause: '',
    unqualifiedMeasure: '',
});

onMounted(()=>{
    Fan();
})

const Fan=()=>{
    read.get("p2-read/api/Report/ShowReport",{
        params:{
            reportId:route.query.reportId,
        }
    })
    .then(res=>{
        form.inspectionStandards = res.data.data[0].inspectionStandards;
        form.testResults = res.data.data[0].testResults;
        form.unqualifiedNum = res.data.data[0].unqualifiedNum;
        form.hegeNum = res.data.data[0].hegeNum;
        form.unqualifiedCause = res.data.data[0].unqualifiedCause;
        form.unqualifiedMeasure = res.data.data[0].unqualifiedMeasure;
        console.log("反填信息内容",res.data.data);
    })
}

const onSubmit = () => {
    write.post("p2-write/api/Report/UpdReport", form)
        .then(res => {
            if (res.data.code == 200) {
                ElMessage.success(res.data.msg);
                router.push('/QueryReport')
            }
            else {
                ElMessage.error(res.data.msg);
                return;
            }
        })
}

</script>

<style scoped>
.order-table {
    border-collapse: collapse;
    width: 100%;
}

.order-table th,
.order-table td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: left;
}

.order-table th {
    background-color: #f2f2f2;
}
</style>

<style scoped>
#app {
    padding: 20px;
}
</style>